import axios from "axios";
import Vue from "vue";
import Stores from "@/utils/store";
import { TOKEN_key } from "@/utils/constant";
// axios.defaults.baseURL = "http://172.16.10.172:8090";
// axios.defaults.baseURL = "http://172.16.13.141:8090";
// axios.defaults.baseURL = "http://172.16.13.26:8090";
axios.defaults.baseURL = "http://172.16.13.212:8090";
axios.defaults.timeout = 5000;
//请求拦截器
axios.interceptors.request.use((config) => {
  //   config.headers.Authorization = localStorage.getItem("token");
  //   return config;
  //可以设置携带token信息
  // config.headers.Authorization = getStore(TOKEN_key)
  config.headers.token = window.localStorage.getItem("token");
  return config;
}),
  (err) => {
    return Promise.reject(err);
  };
//响应拦截器
axios.interceptors.response.use((response) => {
  return response.data;
}),
  (err) => {
    if (err.response) {
      console.log(err.response + "***************");
      switch (err.response.status) {
        case 401:
          Vue.prototype.$message.warning("登录过期，请重新登录");
          break;
      }
    }
    return Promise.reject(err);
  };
export default axios;
